home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmille / Source / DragCoordinator.m < prev    next >
Text File  |  1991-01-11  |  3KB  |  122 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "DragCoordinator.h"
  5. #import    "CardHolder.h"
  6. #import    "GameCoordinator.h"
  7. #import    "StackView.h"
  8. #import    <appkit/View.h>
  9. #import    <objc/List.h>
  10.  
  11.  
  12.                                                 // Recursivly search through the view hierarchy looking
  13.                                                 //    for a tracking view.
  14.     static CardHolder    *findTrackingView( View * , const NXPoint *  );
  15.     
  16.  
  17. @implementation DragCoordinator
  18.  
  19. - setTarget:anObject
  20. {
  21.     target = anObject;
  22.     return self;
  23. }
  24.  
  25. - cardDragged:( const NXPoint * )dragPoint
  26. {
  27.  
  28.     CardHolder    *receivingView = findTrackingView([ gameWindow contentView ], dragPoint );
  29.     
  30.     
  31.                                                     // Handle highlighting.
  32.                                                     //    If you notice very carefully I send messages to the
  33.                                                     //    value nil.  Doesn't bother me.  Bother you?
  34.     if( receivingView ) {
  35.                                                     
  36.                                                     // We're over a tracking view.
  37.                                                     //    Unhighlight the old tracking view and highlight
  38.                                                     //    the new view--if they're different.
  39.         if( currentTrackView != receivingView ) {
  40.             [ currentTrackView    trackingHighlighted:NO ];
  41.             [ receivingView        trackingHighlighted:YES ];
  42.             currentTrackView = receivingView;
  43.         }
  44.     } else {
  45.     
  46.                                                     // We're not over a tracking view.  
  47.                                                     //    Unhighlight the old tracking view.
  48.         [ currentTrackView trackingHighlighted:NO ];
  49.         currentTrackView = nil;
  50.     }
  51.     
  52.     return self;
  53. }
  54.  
  55.  
  56. - cardReleased:aCard at:( const NXPoint * )releasePoint
  57. {
  58.  
  59.     CardHolder    *receivingView = findTrackingView([ gameWindow contentView ], releasePoint );
  60.     
  61.     
  62.     if( receivingView ) {
  63.         CardHolder    *oldHolder = [[ aCard superview ] baseHolder ],
  64.                     *newHolder = [ receivingView baseHolder ];
  65.                     
  66.                                                     // Inform the target of the card movement.
  67.                                                     //    It will decide if the move is valid and if so it
  68.                                                     //    will perform the view disconnect/connect.
  69.         [ target card:aCard movedFrom:oldHolder to:newHolder ];
  70.     } else
  71.                                                     // Card wasn't released over a tracking view.
  72.                                                     //    Beep.
  73.         NXBeep ();
  74.  
  75.                                                     // Unhighlight the previous tracking view.
  76.     [ currentTrackView trackingHighlighted:NO ];
  77.     currentTrackView = nil;
  78.  
  79.     return self;
  80. }
  81.  
  82.  
  83.                                                     // Hits are tricky things.
  84.                                                     //    If you're moving a card over a stack then the
  85.                                                     //    hitTest: method will return the stack;  Hovever, if
  86.                                                     //    there is a card on the stack the hitTest: method
  87.                                                     //    returns the card.  Therefore, the view returned
  88.                                                     //    by hitTest: is recursivly searched until the ultimate
  89.                                                     //    goal is reached.
  90.                                                     // We're looking for a view under the cursor that
  91.                                                     //    is a enabled tracking view.
  92. static CardHolder    *findTrackingView( View *view, const NXPoint *windowPoint )
  93. {
  94.  
  95.     CardHolder    *theView = nil,
  96.                 *hitView = [ view hitTest:windowPoint ];
  97.     
  98.  
  99.     if([ hitView respondsTo:@selector(isTrackingEnabled) ])
  100.         if([ hitView isTrackingEnabled ])
  101.             theView = hitView;
  102.  
  103.     if( !theView ) {
  104.         do {
  105.             if( hitView = [ hitView superview ]) {
  106.                 NXRect        boundsRect;
  107.                 NXPoint        mousePoint = *windowPoint;
  108.                     
  109.                 if([[[ hitView getBounds:&boundsRect ] convertPoint:&mousePoint fromView:nil ] mouse:&mousePoint inRect:&boundsRect ]) 
  110.                     if([ hitView respondsTo:@selector(isTrackingEnabled) ])
  111.                         if([ hitView isTrackingEnabled ])
  112.                             theView = hitView;
  113.             }
  114.         } while( !theView && hitView );
  115.     }
  116.     
  117.     return theView;
  118. }
  119.  
  120.  
  121. @end
  122.